package com.laiyizhan.common.code;

/**
 * 返回码实现
 * Created by folie on 2016/12/22.
 */
public enum CommonRspCode implements RspCode {

    SUCCESS("请求成功", "0"),
    PARAMBUG("参数不完整", "40004"),
    BUSINESS_FAILD("业务错误", "40006"),
    SIGNATURE_FAIL("验签失败", "40010"),
    DB_ERROR("数据库异常", "40097"),
    SYS_ERROR("系统错误", "40099"),

    /** 系统 */

    ERROR("异常", "40003"),

    FAILD("失败", "40005"),

    FORMAT_FAIL("请求数据格式非法", "40060"),
    VERIFY_FAIL("请求数据校验失败", "40062"),
    DATA_NOT_EXIST("数据不存在", "40070"),
    DATA_REPEAT("数据重复", "40071"),
    ROLE_ERROR("权限不足", "40091"),

    /** 远程异常 */

    SYS_TIMEOUT("系统超时", "40098"),

    REST_ERROR("rest异常", "40096"),

    /** 连接 */
    TIMEOUT("连接超时失效", "40011"),
    ILLEGAL_IP("请求IP非法", "40061"),

    UNKNOWN_ERROR("未知异常", "49999");

    private String value;

    private String chName;

    private CommonRspCode(String chName, String value) {
        this.value = value;
        this.chName = chName;
    }

    @Override
    public String getCode() {
        return value;
    }

    @Override
    public String getName() {
        return chName;
    }

    public static CommonRspCode getEnum(String value) {
        CommonRspCode[] crc = CommonRspCode.values();
        for (int i = 0; i < crc.length; i++) {
            if (crc[i].getCode().equals(value)) {
                return crc[i];
            }
            i++;
        }
        return null;
    }
}